package net.zjitc.service.Impl;

import net.zjitc.mapper.ProductMapper;
import net.zjitc.pojo.Product;
import net.zjitc.pojo.ProductExample;
import net.zjitc.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author admin
 * @Date 2019/4/29 10:19
 */
@Service
@Transactional
public class ProductServiceImpl implements ProductService {

    @Autowired
    ProductMapper productMapper;

    @Override
    public List<Product> findAll() {
        return productMapper.selectByExample(null);
    }

    @Override
    public Product findById(String id) {
        return productMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Product> findByJavaName() {
        ProductExample example = new ProductExample();
        example.or().andNameLike("%Java%");
        return productMapper.selectByExample(example);
    }

    @Override
    public List<Product> findByJavaNameAndCid() {
        ProductExample example = new ProductExample();
        example.or().andCidEqualTo(3).andNameLike("%Java%");
        return productMapper.selectByExample(example);
    }

    @Override
    public List<Product> findByJavaNameAndCidOr() {
        ProductExample example = new ProductExample();
        example.or().andCidEqualTo(3).andNameLike("%Java%");
        example.or().andCidEqualTo(1);
        return productMapper.selectByExample(example);
    }

//    按商品价格排序
    @Override
    public List<Product> findByPrice() {
        ProductExample example = new ProductExample();
        example.setOrderByClause("price desc");
        return productMapper.selectByExample(example);
    }

}
